package com.credithc.customers.base.mapper;

import com.credithc.baseserv.core.mapper.BsBaseMapper;
import com.credithc.customers.base.po.UnifySmsPwdFlowPo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author fby
 * @date 2020/03/20 10:44
 */
@Mapper
@Repository
public interface UnifySmsPwdMapper extends BsBaseMapper<UnifySmsPwdFlowPo> {
    @Select("SELECT id AS id, sms_code AS smsCode,create_time AS createTime FROM cust_sms_pwd_flow WHERE phone = #{phone} and sub_system_sign = #{subSystemSign} and create_time > #{today} and create_time < #{tomorrow} and status = 1 and type = #{type} " +
            " ORDER BY create_time DESC ")
    List<UnifySmsPwdFlowPo> getSmsFLowToday(@Param("subSystemSign") String subSystemSign, @Param("phone") String phone, @Param("today") String today, @Param("tomorrow") String tomorrow, @Param("type") String type);

    @Select("SELECT sms_code AS smsCode,unlock_time AS unlockTime FROM cust_sms_pwd_flow WHERE phone = #{phone} and sub_system_sign = #{subSystemSign} and status = 1 and type = #{type} " +
            " ORDER BY create_time DESC LIMIT 1")
    UnifySmsPwdFlowPo getSmsFLow(@Param("subSystemSign") String subSystemSign, @Param("phone") String phone, @Param("type") String type);

    @Select("SELECT sms_code AS smsCode FROM cust_sms_pwd_flow WHERE phone = #{phone} and sub_system_sign = #{subSystemSign} and sms_code = #{smsCode} and type = #{type} and create_time > DATE_SUB(NOW(), INTERVAL 10 MINUTE) " +
            " ORDER BY create_time DESC LIMIT 1")
    UnifySmsPwdFlowPo getSmsCodeRecently(@Param("subSystemSign") String subSystemSign, @Param("phone") String phone, @Param("smsCode") String smsCode, @Param("type") String type);
}
